package com.atguigu.paymentdemo.config;

import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.core.http.AbstractHttpClient;
import com.wechat.pay.java.core.http.DefaultHttpClientBuilder;
import com.wechat.pay.java.core.http.HttpClient;
import com.wechat.pay.java.core.http.okhttp.OkHttpClientAdapter;
import com.wechat.pay.java.core.notification.NotificationConfig;
import com.wechat.pay.java.core.notification.RSACombinedNotificationConfig;
import com.wechat.pay.java.service.billdownload.BillDownloadService;
import com.wechat.pay.java.service.payments.nativepay.NativePayService;
import com.wechat.pay.java.service.refund.RefundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @projectName: payment-demo
 * @package: com.atguigu.paymentdemo.config
 * @className: WxConfig
 * @author: 躺着认真玩
 * @description: 微信支付服务配置
 * @date: 2025/6/8 20:48
 * @version: 1.0
 */
@Configuration
public class WxConfig {
    @Autowired
    private WxPayConfig wxPayConfig;
    @Bean
    public Config creat(){
        // 自动更新微信支付平台证书
        Config config =
                new RSAAutoCertificateConfig.Builder()
                        .merchantId(wxPayConfig.getMchId())
                        .privateKeyFromPath(wxPayConfig.getPrivateKeyPath())
                        .merchantSerialNumber(wxPayConfig.getMchSerialNo())
                        .apiV3Key(wxPayConfig.getApiV3Key())
                        .build();
        return config;
    }

    @Bean
    public NativePayService creatService(Config config){
        // 构建service
        NativePayService service = new NativePayService.Builder().config(config).build();
        return service;
    }

    @Bean
    public RefundService creatRefuseService(Config config){
        // 构建service
        RefundService refundService = new RefundService.Builder().config(config).build();
        return  refundService;
    }

    @Bean
    public BillDownloadService creatBillDownloadService(Config config){
        BillDownloadService service = new BillDownloadService.Builder().config(config).build();
        return service;
    }

}
